package cn.itcast.www.jspservletTest;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.Tag;
import javax.servlet.jsp.tagext.TagSupport;
//switch标签case部分
public class CaseTag extends TagSupport {
	private boolean cond;
	
	public CaseTag(){
		cond = false;
	}
	
	public void release(){
		cond = false;
	}
	//标签参数，成立条件
	public void setCond(boolean cond){
		this.cond = cond;
	}

	@Override
	public int doStartTag() throws JspException {
		Tag parent = this.getParent();
		
		//判断是否可以执行自身的标签体
		if(!((SwitchTag)parent).getPermission()){
			return SKIP_BODY;
		}
		//如果条件为true,则通知父标签，已经有一个子标签满足条件了。否则，忽略标签体
		if(cond){
			((SwitchTag)parent).subTagSucceeded();
			return EVAL_BODY_INCLUDE;
		}else{
			return SKIP_BODY;
		}	
	}	
}
